Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix GetBestMiningCandidate bug #3444

Conversation

IPFSMain-Official
Copy link

If ChainTipSetWeight returns an error, waiting outside for 5 seconds to try again will still report an error, resulting in an infinite loop, the miner can not dig properly block.

the error:
2020-09-01T11:31:50.596+0800 ERROR miner miner/miner.go:159 failed to get best mining candidate: loading tipset {bafy2bzacebaq24x6umldnhmr5fdsbd6zd44qqehkrioxavasgkmrqyckpm7es}: get block bafy2bzacebaq24x6umldnhmr5fdsbd6zd44qqehkrioxavasgkmrqyckpm7es: blockstore: block not found

@@ -303,6 +303,7 @@ func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error)
}
ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.TipSet.Key())
if err != nil {
m.lastWork = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the actual bug being fixed here? Shouldnt we also have the same line copied a few lines up?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lotus/miner/miner.go

func (m *Miner) mine(ctx context.Context) {
	...
	for {
		prebase, err := m.GetBestMiningCandidate(ctx)
		// If an error occurs in GetBestMiningCandidate, it will wait 5 seconds to retry GetBestMiningCandidate
		if err != nil {
			log.Errorf("failed to get best mining candidate: %s", err)
			m.niceSleep(time.Second * 5)
			continue
		}
		...
	}
	...
}

func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error) {
	...
	if m.lastWork != nil {
		if m.lastWork.TipSet.Equals(bts) {
			return m.lastWork, nil
		}

		btsw, err := m.api.ChainTipSetWeight(ctx, bts.Key())
		if err != nil {
			return nil, err
		}
		ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.TipSet.Key())
		// If lastWork is using an incorrect TipSet, an error is received and returned here, 
		// for example i have got: blockstore: block not found. 
		// There is no modification lastWork here, so if you try it again, you will get the same error here. 
		// In the mine() function above, it tries again and again, but always got this error
		if err != nil {
			return nil, err
		}
		...
	}
	...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thank you for that. This makes sense

Signed-off-by: Jakub Sztandera <[email protected]>
@Kubuxu Kubuxu force-pushed the fix-GetBestMiningCandidate-bug branch from 40cec12 to a23ab12 Compare October 8, 2020 21:40
@magik6k magik6k merged commit 2d3b616 into filecoin-project:master Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants